Skip to content

fix(version-ls): clamp --limit to slice length to avoid panic (#1662)#1663

Open
SAY-5 wants to merge 1 commit into
k3d-io:mainfrom
SAY-5:say5/k3d-version-ls-limit-clamp-1662
Open

fix(version-ls): clamp --limit to slice length to avoid panic (#1662)#1663
SAY-5 wants to merge 1 commit into
k3d-io:mainfrom
SAY-5:say5/k3d-version-ls-limit-clamp-1662

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 12, 2026

Copy link
Copy Markdown

What

Guard the slice expression that applies the `--limit` flag in `k3d version list` so it does not panic when the limit is larger than the number of filtered tags.

Why

Closes #1662. Reproduced exactly as reported:

```
k3d version list -i '^1.333' -l 1 -o repo k3s
panic: runtime error: slice bounds out of range [:1] with capacity 0
```

Root cause: `filteredTags[0:flags.limit]` indexes the slice without checking the slice length, so any include-regexp that matches zero tags (or fewer tags than `--limit`) trips the runtime check.

Implications

CLI-only change in `cmd/root.go`. The limit now silently clamps to `len(filteredTags)`, matching the documented intent (truncate output). Added `cmd/root_test.go` covering the regression and surrounding boundary cases.

…#1662)

When no tags match the include regexp, filteredTags is empty and the
expression filteredTags[0:flags.limit] panicked with
'slice bounds out of range [:N] with capacity 0'.

Guard the slice expression with a length check so an over-sized limit
is silently clamped, matching the documented behaviour where limit just
truncates the output.

Signed-off-by: SAY-5 <say.apm35@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] k3d version list -i ... -l 1 fails if ... doesn't match

2 participants